<?php
namespace Admin\Model;
use Common\Model\CommonModel;
class SlideModel extends  CommonModel{
	
	//自动验证
	protected $_validate = array(
			//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
			array('title', 'require', '名称不能为空！', 1, 'regex', 3),
			array('catid', 'require', '分类不能为空！', 1, 'regex', 3),
			array('thumb', 'require', '图片不能为空！', 1, 'regex', 3),
		
		
	);
	
	/**
	 * 后台有更新/编辑则删除缓存
	 * @param type $data
	 */
	public function _before_write() {
		parent::_before_write();
		$this->data_cache();
	}
	public function _after_insert() {
		parent::_after_insert();
		$this->data_cache();
	}
	//删除操作时删除缓存
	public function _after_delete() {
		parent::_after_delete();
		$this->data_cache();
	}
	public function data_cache(){
		
	$data=$this->where(array("status"=>1))->order(array("listorder" => "DESC","id"=>"DESC"))->select();
		
		
	
		foreach ($data as $k=>$v){
				
			$result[$v[catid]][]=$v;
		
		}
		
		F("Slide",$result);
	}
	
}